/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: ContextHolder.java
 * Author: YuXingZh
 * Date: 10/6/2024 上午12:09
 * Description:
 * token维护
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package com.bosssoft.g1.config;

import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

/**
 * @className: ContextHolder
 * @description: 解决什么问题：
 * 演示线程池的正确使用
 * 主要方法和数据成员：
 * methodxx 使用 ThreadPoolExecutor创建线程进行任务操作
 * 注意事项：
 * 例如：该类需要从容器获取不可以new
 * @author: YuXingZh
 * @date: 10/6/2024上午12:09
 * @since 1.0
 **/
@Component
public class ContextHolder {

    private static final ThreadLocal<Map<String, String>> THREAD_LOCAL = ThreadLocal.withInitial(HashMap::new);


    public  void setUserCode(String code, String token) {
        THREAD_LOCAL.get().put(code, token);
    }

    public  String getUserCode(String code) {
        return THREAD_LOCAL.get().get(code);
    }

    public  void clear() {
        THREAD_LOCAL.remove();
    }
}
